package com.starter.home.controller;


import com.starter.home.domain.entity.ServeType;
import com.starter.home.domain.vo.TypeVO;
import com.starter.home.service.IServeTypeService;
import com.starter.home.util.OptionVO;
import com.starter.home.util.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author
 * @since 2020-04-30
 */
@RestController
@RequestMapping("/type")
public class TypeController {

    @Autowired
    private IServeTypeService typeService;

    @GetMapping(value = "/getParentIds")
    public ResponseResult getParentIds(){
        List<ServeType> parentIds = typeService.getParentIds();
        return ResponseResult.success(parentIds);
    }

    @GetMapping(value = "/getList")
    public ResponseResult getList(){
        List<TypeVO> list = typeService.getList();
        return ResponseResult.success(list);
    }

    @PostMapping(value = "/delete/{id}")
    public ResponseResult delete(@PathVariable Integer id){
        typeService.deleteById(id);
        return ResponseResult.success(null);
    }

    @PostMapping(value = "/add")
    public ResponseResult add(@RequestBody ServeType serveType){
        boolean save = typeService.save(serveType);
        if (save){
            return ResponseResult.success(null);
        }else {
            return ResponseResult.error(null);
        }
    }

    @GetMapping(value = "/getChildren")
    public ResponseResult getChildren(){
        List<OptionVO> list = typeService.getChildren();
        return ResponseResult.success(list);
    }


}
